<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script src="${path}/portal/js/plugin/ajaxfileupload.js"></script>
<%
	request.setAttribute("path", request.getContextPath());
%>
<script type="text/javascript">

function selectFile( inputFileId ){
	$("#" + inputFileId).click();
	return false;
}
function modifyImage(formId,inputFileId,imageId){
	
	var obj = document.getElementById(inputFileId);
	var res = common.checkUserImage(obj);
	if(res){
		$form = $("#"+formId);
		var url = $form.attr("action") + "?imageFileId=" + inputFileId;
		uploadImage(url,inputFileId);
	}
}


function uploadImage(url,inputFileId){
	common.progressDialog("上传中...");
	$.ajaxFileUpload ({
	    url:url, 
	    secureuri:false, 
	    fileElementId:inputFileId,
	    dataType:'json', 
	    success: function (result) {
	    	 common.closeProgressDialog();
		     if(result.type == "1"){
		    	 common.modalGlobalMessage("上传图片失败!","错误"); 
	   		 }else if(result.type == "2"){
	   			common.modalGlobalMessage("系统出现异常了!","异常"); 
	   		 }else if(result.type == "3"){
	   		 	 $("#userImageId").attr("src",result.content.thumbImgFullPath);
	   			 $("#imageId").val(result.content.id);
	   		 }else{
	   			common.modalGlobalMessage("系统出现异常了!","异常");  
	   		 }
	    }
	  });
}

</script>
				
<form  id="uploadForm" class="form-horizontal" action="${root}/app/image/upload" method="post">
<div class="control-group">
	<label class="control-label">照片:</label>
	<div class="controls">
		<c:choose>
			<c:when test="${user.image != null}">
				<img src="${user.image.thumbImgFullPath}" id="userImageId" style="width: 150px;height: 150px" alt="" class="img-rounded" >
			</c:when>
			<c:otherwise>
				<img src="${path}/portal/css/images/def_img.jpg" id="userImageId" alt="" class="img-rounded" >
			</c:otherwise>
		</c:choose>
	</div>
</div>
<div class="controls controls-row">
	<input type="hidden" />
    <input type="file"  onchange="common.checkUserImage(this)" name="userImageFile"  id="userImageFile" >
    <button type="button"  class="btn btn-primary" onclick="modifyImage('uploadForm','userImageFile','')" >上传</button>
</div>
</form>
